import request from '@/utils/request';


// 获取分类树
export function fetchCategoryTree() {
  console.log('Calling fetchCategoryTree API');
  return request({
    url: '/supply/type/typeTree',
    method: 'get'
  }).then(response => {
    console.log('TypeTree API response:', response);
    return response;
  }).catch(error => {
    console.error('TypeTree API error:', error);
    // 如果接口调用失败，返回Mock数据
    return {
      code: 200,
      data: [
        {
          id: 1,
          name: '电子产品',
          children: [
            {
              id: 11,
              name: '手机',
              children: [
                { id: 111, name: '智能手机' },
                { id: 112, name: '功能手机' }
              ]
            },
            {
              id: 12,
              name: '电脑',
              children: [
                { id: 121, name: '笔记本电脑' },
                { id: 122, name: '台式电脑' }
              ]
            }
          ]
        },
        {
          id: 2,
          name: '食品',
          children: [
            {
              id: 21,
              name: '饮料',
              children: [
                { id: 211, name: '碳酸饮料' },
                { id: 212, name: '果汁' }
              ]
            },
            {
              id: 22,
              name: '零食',
              children: [
                { id: 221, name: '薯片' },
                { id: 222, name: '饼干' }
              ]
            }
          ]
        }
      ]
    };
  });
}
